package algorithm.killDragon;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        int index=0;
        while(s.hasNext()){
            int n=s.nextInt();
            int m=s.nextInt();
            if(m!=0){
                index=new Random().nextInt(m);
            }
            for(int i=0;i<n;i++){
                String op=s.next();
                int index1=s.nextInt();
                index=OpABBinary(index,index1,op);
            }
            System.out.println(index);
        }
    }
    public static int OpABBinary(int a,int b,String op){
        int index;
        String aa=Integer.toBinaryString(a);
        String bb=Integer.toBinaryString(b);
        int aal=aa.length();
        int bbl = bb.length();
        if (aal>bbl){
            for(int i=0;i<aal-bbl;i++){
                bb="0"+bb;
            }
        }
        else {
            for(int i=0;i<bbl-aal;i++){
                aa="0"+aa;
            }
        }
        switch (op){
            case "AND":
                index=AND(aa,bb);
                break;
            case "OR":
                index=OR(aa,bb);
                break;
            case "XOR":
                index=XOR(aa,bb);
                break;
                default:
                    index=0;
                    break;

        }
        return index;
    }
    public static int AND(String a,String b){
        char[] aa=a.toCharArray();
        char[] bb=b.toCharArray();
        String sAnd="";
        for (int i=0;i<a.length();i++){
            if(Integer.parseInt(String.valueOf(aa[i]))==1&&Integer.parseInt(String.valueOf(bb[i]))==1){
                sAnd+="1";
            }
            else {
                sAnd+="0";
            }
        }
        return Integer.parseInt(sAnd,2);
    }
    public static int OR(String a,String b){
        char[] aa=a.toCharArray();
        char[] bb=b.toCharArray();
        String sOr="";
        for (int i=0;i<a.length();i++){
            if(Integer.parseInt(String.valueOf(aa[i]))==1||Integer.parseInt(String.valueOf(bb[i]))==1){
                sOr+="1";
            }
            else {
                sOr+="0";
            }

        }
        return Integer.parseInt(sOr,2);
    }
    public static int XOR(String a,String b){
        char[] aa=a.toCharArray();
        char[] bb=b.toCharArray();
        String sXor="";
        for (Integer i=0;i<a.length();i++){
            if(Integer.parseInt(String.valueOf(aa[i]))!=Integer.parseInt(String.valueOf(bb[i]))){
                sXor+="1";
            }
            else {
                sXor+="0";
            }

        }
        return Integer.parseInt(sXor,2);
    }
}
